﻿using University.Workshop.Business;
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Tests
{
    [TestClass]
    public class ProductUnsubscribeManagerTest
    {
        [TestMethod]
        public void SuccesfullUnsubscribe()
        {
            Random rand = new Random();
            string email = "diroag" + rand.Next(500) + "@hotmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            string name = "Some sort of title for the product";
            string price = "10000"; // TODO: Initialize to an appropriate value
            string description = "This is an example of a valid description which is long enough to be accepted"; // TODO: Initialize to an appropriate value
            string category = "Electronics";
            string currency = "Bolivianos";
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                             birthday, email, "qwerty12", "qwerty12", "Cochabamba",
                             "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product actual;
            actual = ProductRegistrationManager.RegisterNewProduct(name, price, description, category, true, currency, user.Id, "1");
            actual = ProductUnsubscribeManager.UnsubscribeProduct(actual.ProductId);
            Assert.AreNotEqual(null, actual);
            Assert.AreEqual(name, actual.Name);
            Assert.AreEqual("Down", actual.Status);
        }

        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void FailedOnAuctionProductUnsubscribing()
        {
            string name = "product on auction";
            string price = "10000"; // TODO: Initialize to an appropriate value
            string description = "This is an example of a valid description which is long enough to be acceptedasdasd"; // TODO: Initialize to an appropriate value
            string category = "Electronics";
            string currency = "Bolivianos";
            long sellerID = 1;
            Product actual;
            actual = ProductRegistrationManager.RegisterNewProduct(name, price, description, category, true, currency, sellerID,"1");
            actual = ProductRegistrationManager.ModifyProduct(name, price, description, category, true, currency, actual.ProductId, "OnAuction","1");
            actual = ProductUnsubscribeManager.UnsubscribeProduct(actual.ProductId);
            Assert.AreNotEqual(null, actual);
            Assert.AreEqual(name, actual.Name);
            Assert.AreEqual("Down", actual.Status);
        }
    }
}
